﻿using UnityEngine;
using System.Collections;

public class test1 : MonoBehaviour 
{

	IEnumerator Start() 
    {
        Debug.Log(Time.time);
        /*
        Debug.Log("Start DownloadImage()");
        WWW www = new WWW("parad.eagle.ru/Images/Magazines/115.jpg");
        yield return StartCoroutine(DownloadImage());
        Debug.Log(www.texture.height);
        Debug.Log("Stop DownloadImage()");


        Debug.Log("Start Timer()");
        yield return StartCoroutine(Timer());
        Debug.Log("Stop Timer()");

        
        Debug.Log("Start TestYield()");
        foreach (int i in TestYield(2, 8))
            Debug.Log(i);
        Debug.Log("Stop TestYield()");
        Debug.Log(TestYield(2, 8).GetEnumerator().Current);

        
        foreach(int i in TestYield2())
            Debug.Log(i);
        Debug.Log("Stop TestYield2()");
        
        Debug.Log("11111");
        Debug.Log("Start TestYield3()");
        TestYield3();
        Debug.Log("Stop TestYield3()");
        Debug.Log("11111");
        */

        /*
        Debug.Log("Start DownloadImage2()");
        StartCoroutine(DownloadImage2());
        Debug.Log("Stop DownloadImage2()");
        */
        
        
        Debug.Log("222222");
        Debug.Log("Start TestYield3()");
        StartCoroutine(TestYield3());
        Debug.Log("Stop TestYield3()");
        Debug.Log("222222");
        
        
        
        Debug.Log("333333");
        Debug.Log("Start TestYield3()");
        yield return StartCoroutine(TestYield3());
        Debug.Log("Stop TestYield3()");
        Debug.Log("333333");
        
	}

    IEnumerator DownloadImage()
    {
        
        WWW www = new WWW("parad.eagle.ru/Images/Magazines/115.jpg");
        yield return www;
        
    }

    IEnumerator Timer()
    {
        Debug.Log(Time.time);
        yield return new WaitForSeconds(1);
        Debug.Log(Time.time);
    }

    IEnumerable TestYield(int i, int power)
    {
        int result = 1;
        int c = 0;
        while (c++ < power)
        {
            result *= i;
            Debug.Log("     " + result);
            yield return result;
        }
    }

    IEnumerable TestYield2()
    {
        int i = 0;
        while (i++ < 100)
        {
            if (i > 10)
            {
                yield break;
            }
            yield return i;
        }
    }

    IEnumerator TestYield3()
    {
        int i = 0;
        while (true)
        {
            i++;
            if (i > 10)
            {
                yield break;
            }
            Debug.Log(i);
            yield return i;
        }
    }

    IEnumerator DownloadImage2()
    {

        WWW www = new WWW("newevolutiondesigns.com/images/freebies/hd-wallpaper-1.jpg");
        while (true)
        {                
            Debug.Log("...");
            if (www.texture == null)
            {

                yield return www;
            }
            else
            {
                Debug.Log(www.bytes.Length);
                yield break;
            }
        }

    }


    void OnClick()
    {
        Texture2D texture = new Texture2D(1000, 1000, TextureFormat.RGB24, false);
        //GameObject.Destroy(texture);
        Debug.Log("Click");
    }
	
    void Update() 
    {
        //Debug.Log("         I AM UPDATE()");	
	}
}
